#include "dialog_regist.h"
#include "ui_dialog_regist.h"
#include <QDebug>
Dialog_Regist::Dialog_Regist(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog_Regist)
{
    ui->setupUi(this);
    this->setWindowTitle("Regist");                      //设置程序显示名字
    this->setWindowIcon(QIcon(":/logo/Images/Dog_logo.png"));   //设置程序图标
    ui->label_text_1->setStyleSheet("border-image:url(:/Redist/Images/Regist/User.png)");               //设置样式表
    ui->label_text_5->setStyleSheet("border-image:url(:/Redist/Images/Regist/infor.png)");              //设置样式表
    //数据初始化
    regist_date.doginfor.dog_Type =0;               //初始化类型
    regist_date.doginfor.dog_StrongPoint =0;        //初始化特征
    ui->comboBox_2->setEnabled(false);              //灰掉
}

Dialog_Regist::~Dialog_Regist()
{
    delete ui;
}
void Dialog_Regist::message_1()
{
    int x = QMessageBox::warning(this,"警告","用户名存在",QMessageBox::Yes);               //弹出警告窗口
    if(x == QMessageBox::Yes)
    {
        ui->lineEdit_name->clear();                     //清空用户名输入框
    }
}

void Dialog_Regist::message_2()
{
    int x = QMessageBox::warning(this,"提示","用户注册成功",QMessageBox::Yes);
    if(x == QMessageBox::Yes)
    {
        emit set_user_name_password();                          //触发自动填写用户名密码函数
        this->close();                          //关闭该窗口
    }
}

void Dialog_Regist::message_3()
{
    QMessageBox::warning(this,"警告","注册失败，请检查注册信息",QMessageBox::Yes);            //弹出警告窗口
}
/*
 * 设置用户名
 */
void Dialog_Regist::set_user_name(QString username)
{
    ui->lineEdit_name->setText(username);                           //设置用户名
}
/*
 * 点击注册按钮操作
 * 获取用户输入数据
 * 格式化整理用户数据
 * 触发注册信号
 */
void Dialog_Regist::on_pushButton_clicked()
{
    if ((!ui->lineEdit_name->text().isEmpty())&&(!ui->lineEdit_dog_name->text().isEmpty())&&(!ui->lineEdit_password->text().isEmpty())&&(!ui->lineEdit_passwordr->text().isEmpty()))                //判定是否符合注册数据标准
    {
        regist_date.succeed_Flag =0;                                                            //设置注册标志位
        regist_date.userinfor.user_Name=ui->lineEdit_name->text();             //赋值
        regist_date.userinfor.user_Password=ui->lineEdit_password->text();     //赋值
        regist_date.userinfor.user_Phone=ui->lineEdit_phone->text();           //赋值
        regist_date.userinfor.user_Email=ui->lineEdit_email->text();           //赋值
        regist_date.userinfor.user_QQ=ui->lineEdit_qq->text();
        regist_date.userinfor.user_Money="50";//赋值
        regist_date.doginfor.dog_Name=ui->lineEdit_dog_name->text();          //赋值
        regist_date.doginfor.dog_Age = 0;       //赋值
        regist_date.doginfor.dog_Energy = 100;  //赋值
        regist_date.doginfor.dog_Health = 100;  //赋值
        if(regist_date.doginfor.dog_Type==0){
            regist_date.doginfor.dog_Wasteful = 20;  //赋值
        }else if(regist_date.doginfor.dog_Type==1){
            regist_date.doginfor.dog_Wasteful = 30;  //赋值
        }else{
            regist_date.doginfor.dog_Wasteful = 40;  //赋值
        }

        emit regist_to_server();                //触发发送信号
    }
    else
    {
        QMessageBox::warning(this,"警告","用户信息不完整",QMessageBox::Yes);             //弹出警告信息
    }
}
/*
 * 获取类型
 */
void Dialog_Regist::on_comboBox_activated(int index)
{
    regist_date.doginfor.dog_Type =index;                //获取对应的值

    qDebug()<<regist_date.doginfor.dog_Type;
}
/*
 * 获取特长
 */
void Dialog_Regist::on_comboBox_2_activated(int index)
{
    regist_date.doginfor.dog_StrongPoint =index;                    //获取对心的值
}
/*
 * 获取用户名
 * 触发用户名比较信号
 */
void Dialog_Regist::on_lineEdit_name_editingFinished()
{
    regist_date.userinfor.user_Name = ui->lineEdit_name->text();                       //获取用户名
    emit compare_user_name();                                   //触犯用户名比较函数
}
/*
 * 密码重复度比较
 */
void Dialog_Regist::on_lineEdit_passwordr_editingFinished()
{
    if(ui->lineEdit_password->text() != ui->lineEdit_passwordr->text())             //判定两次密码是否相同
    {
        int x =QMessageBox::warning(this,"警告","用户密码两次输入有误",QMessageBox::Yes);           //弹出警告窗口
        {
            if(x == QMessageBox::Yes)               //点击YES按钮
            {
                ui->lineEdit_passwordr->clear();                        //将密码第二个清空
                ui->lineEdit_password->clear();
                ui->lineEdit_password->setFocus();                     //设置焦点在该输入框中
            }
        }
    }
}
